<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑节点</title>
</head>
<body>
<script type="text/html" id="form">
    <input type="hidden" name="id" value="{{ d.id }}"/>
    <div class="mainBox">
        <div class="main-container">
            <blockquote class="layui-elem-quote">基础信息</blockquote>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    地图名称</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{{d.title}}" lay-verify="required" autocomplete="off" placeholder="请输入地图名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <text style="color:red;">支持jpg、png，大小不超过5M，图片尺寸建议 3:2比例</text>
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    地图图片</label>
                <div class="layui-input-block">
                    <div class="laytpUpload"
                         data-name="img"
                         data-dir="xm_game/map/content/img"
                         data-accept="image"
                         data-type="ali-oss"
                         data-layVerify="required"
                         data-showChoiceBtn="false"
                         data-uploadedId="{{d.img}}"
                         data-uploaded="{{d.img}}"
                    ></div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    地图deeplink地址</label>
                <div class="layui-input-block">
                    <input type="text" name="deeplink_url" value="{{d.deeplink_url}}" autocomplete="off" placeholder="请输入地图deeplink地址"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    选择地图标签</label>
                <div class="layui-input-block">
                    <div class="xmSelect"
                         data-name="label_id"
                         data-sourceType="route"
                         data-source="/admin.map.label/index"
                         data-params='{"search_param":{"relation_id":{"value":"{{d.relation_id}}","condition":"="},"status":{"value":1,"condition":"="}}}'
                         data-textField="name"
                         data-valueField="id"
                         data-paging="true"
                         data-radio="false"
                         data-direction="down"
                         data-selected="{{d.label_id}}"
                    ></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    发布者名称</label>
                <div class="layui-input-block">
                    <input type="text" name="author_name" value="{{d.author_name}}" autocomplete="off"
                           placeholder="请输入发布者名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <text style="color:red;">支持jpg、png，大小不超过5M</text>
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    发布者头像</label>
                <div class="layui-input-block">
                    <div class="laytpUpload"
                         data-name="author_img"
                         data-dir="xm_game/map/content/author_img"
                         data-accept="image"
                         data-type="ali-oss"
                         data-layVerify="required"
                         data-showChoiceBtn="false"
                         data-uploaded="{{d.author_img}}"
                         data-uploadedId="{{d.author_img}}"
                    ></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地图介绍</label>
                <div class="layui-input-block" style="width: 400px">
                            <textarea name="description" placeholder="请输入地图介绍" class="layui-textarea"
                                      lay-verify="description">{{d.description}}</textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit=""
                    lay-filter="laytp-form">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form"></form>
<script>
    if (localStorage.getItem("staticDomain")) {
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
    } else {
        document.write("<link rel='stylesheet' href='/static/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        //获取参数ID
        var id = facade.getUrlParam('id');
        if (!id) {
            facade.error('参数ID不能为空');
            return false;
        }

        //获取数据，渲染到对应的节点上
        facade.ajax({
            route: "/admin.map.content/info",
            data: {id: id},
            successAlert: false,
            showLoading: true
        }).done(function (res) {
            if (res.code === 0) {
                layui.laytpl($("#form").html()).render(res.data, function (string) {
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                });
            }
        });
        form.on('submit(laytp-form)', function (data) {
            var btnAnim = layui.button.load({elem: $(this)});
            facade.ajax({
                route: '/admin.map.content/edit',
                data: data.field
            }).done(function (res) {
                if (res.code === 0) {
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("laytp-table");
                }
                btnAnim.stop();
            }).fail(function () {
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>